@extends("layout.main")

@section("content")
    @include("layout.nav")
<div class="layui-container">
    <div class="layui-row layui-col-space15">
        <div class="layui-col-md8 content detail">
            <div class="fly-panel detail-box">
                <?php $question_id = $question->id ; ?>
                <h1>{{$question->title}}</h1>
                <div class="fly-detail-info">
                    <span class="layui-badge layui-bg-green fly-detail-column">{{$question->cate->name}}</span>
                    @if($question -> status == 0)
                    <span class="layui-badge" style="background-color: #999;">未结</span>
                    @else
                    <span class="layui-badge" style="background-color: #999;">已结</span>
                    @endif
                    @if($question-> is_jing == 1)
                    <span class="layui-badge layui-bg-red">精帖</span>
                    @endif
                    <div class="fly-admin-box" data-id="19038"></div>
                    <span class="fly-list-nums">
                                <a href="#comment">
                                    <i class="iconfont" title="回答">&#xe60c;</i>{{count($question->answers)}}</a>
                                <i class="iconfont" title="人气">&#xe60b;</i>{{$question->view_num}}</span></div>
                <div class="detail-about">
                    <a class="fly-avatar" href="/u/6167784/">
                        <img src="{{$question->user->face}}" alt="小巷"></a>
                    <div class="fly-detail-user">
                        <a href="/u/6167784/" class="fly-link">
                            <cite>{{$question->user->name}}</cite>
                            <i class="layui-badge fly-badge-vip">{{$question->user->role}}</i></a>
                        <span>{{$question->created_at->diffForHumans()}}</span></div>
                    <div class="detail-hits" id="LAY_jieAdmin" data-id="19038">
                        <span style="padding-right: 10px; color: #FF7200">悬赏：{{$question->kiss}}飞吻</span>

                        @if($question->oneCollect(\Auth::id())->exists())
                        <span class="layui-btn layui-btn-xs jie-admin layui-btn-danger" duid="{$data.uid}" type="collect" data-type="remove">取消收藏</span>
                        @else
                        <span class="layui-btn layui-btn-xs jie-admin " duid="{$data.uid}" type="collect" data-type="add">收藏</span>
                        @endif
                    </div>
                </div>

                <div class="detail-body photos">
                    <?php $data = json_decode($question->desc,true)?>
                    <table class="layui-table"> <tbody> <tr> <td> 版本: {{$data['project']}} {{$data['version']}}</td> <td>浏览器：{{$data['browser']}}</td> </tr> </tbody> </table>
                    {!! $question->content !!}
                </div></div>
            <div class="fly-panel detail-box" id="flyReply">
                <fieldset class="layui-elem-field layui-field-title" style="text-align: center;">
                    <legend>回帖</legend></fieldset>
                <ul class="jieda" id="jieda">
                    @foreach($answers as $answer)
                    <li data-id="79226">
                        <a name="item-1511310467240"></a>
                        <div class="detail-about detail-about-reply">
                            <a class="fly-avatar" href="/u/1177512/">
                                <img src="{{$answer->user->face}}" alt="Fufu"></a>
                            <div class="fly-detail-user">
                                <a href="/u/1177512/" class="fly-link">
                                    <cite>{{$answer->user->name}}</cite>
                                    <i class="layui-badge fly-badge-vip">{{$answer->user->role}}</i></a>
                            </div>
                            <div class="detail-hits">
                                <span>{{$answer->created_at->diffForHumans()}}</span></div>
                        </div>
                        @if($answer->status == 1)
                        <i class="iconfont icon-caina" title="最佳答案"></i>
                        @endif
                        <div class="detail-body jieda-body photos">{!! $answer->content !!}</div>
                        <div class="jieda-reply">
                            <span class="jieda-zan @if($answer->onezan(\Auth::id())->count()) zanok @endif " answer_id = "{{$answer->id}}" type="zan" >
                                <i class="iconfont icon-zan"></i>
                            <em>{{count($answer->zan)}}</em></span>
                            <a href="#xbs" class="huifu" uid = "{{$answer->user->id}}"  nickname="{{$answer->user->name}}"><span type="reply">
                                        <i class="iconfont icon-svgmoban53"></i>回复</span></a>
                            @if($answer->user->id != \Auth::id() && $question->status == 0)
                            <span theuid="{$v['uid']}" class="jieda-caina" answer_id = "{{$answer->id}}" type="accept" accept="15"> 采纳 </span>
                            @endif
                        </div>
                    </li>
                    @endforeach
                </ul>
                <div id="pull_right">
                    <div class="pull-right">
                        {{$answers->links()}}
                    </div>
                </div>
                <div class="layui-form layui-form-pane">
                    <form method="post">
                        <div class="layui-form-item layui-form-text">
                            <a name="xbs"></a>

                            <div class="layui-input-block">
                                <textarea id="L_content" name="content"  placeholder="请输入内容" class="layui-textarea fly-editor" style="height: 150px;"></textarea>
                            </div>
                        </div>
                        <div class="layui-form-item">
                            <input type="hidden" name = 'question_id' value="{{$question->id}}">
                            <button class="layui-btn" lay-filter="answerAdd" lay-submit>提交回复</button></div>
                    </form>
                </div>
            </div>
        </div>
        <div class="layui-col-md4">
            <dl class="fly-panel fly-list-one">
                <dt class="fly-panel-title">本周热议</dt>
                @foreach($hotQuestions as $question)
                    <dd>
                        <a href="/question/{{$question->id}}/show">{{$question->title}}</a>
                        <span>
                                <i class="iconfont icon-pinglun1"></i>{{$question->answers_count}}</span>
                    </dd>
                @endforeach
            </dl>
            <div class="fly-panel">
                <div class="fly-panel-title">心级赞助商
                    <span style="padding: 0 3px;">-</span>
                    <a href="/jie/15697/" class="fly-link fly-joinad    ">我要加入</a></div>
                <div class="fly-panel-main">
                    <a href="http://core.fineui.com/" target="_blank" rel="nofollow" class="fly-zanzhu" style="background-color: #205B95;" time-limit="2017.07.17-2018.07.18">FineUI - 9 年控件库 + ASP.NET Core 2.0</a>
                    <a href="http://www.ideacms.net/" target="_blank" rel="nofollow" class="fly-zanzhu" style="background-color: #FF7033;" time-limit="2017.09.25-2018.01.26">IdeaMall - 简单易用的商城+分销+小程序</a>
                    <a href="https://www.tpt360.com/" target="_blank" rel="nofollow" class="fly-zanzhu" style="background-color: #009688;" time-limit="2017.11.13-2017.12.14">TPTCMS - 基于 layui 的网站管理系统</a>
                    <a href="http://www.phpyun.com/" target="_blank" rel="nofollow" class="fly-zanzhu" style="background-color: #456DAB" time-limit="2017.10.15-2018.01.16">phpyun - 人才招聘系统+商家小程序</a></div>
            </div>
            <div class="fly-panel">
                <div class="fly-panel-title">官方产品</div>
                <div class="fly-panel-main">
                    <a href="http://layim.layui.com/?from=fly" target="_blank" class="fly-zanzhu" time-limit="2017.09.25-2099.01.01" style="background-color: #5FB878;">LayIM 3.0 - layui 旗舰之作</a></div>
            </div>
            <div class="fly-panel" style="padding: 20px 0; text-align: center;">
                <img  style="max-width: 100%;" alt="layui">
                <p style="position: relative; color: #666;">微信扫码关注 layui 公众号</p></div>
        </div>
    </div>
</div>
<script>
    layui.use(['jquery','layer','form','layedit'], function(){
        var $ = layui.jquery;
        var layer = layui.layer;
        var form = layui.form;
        var layedit = layui.layedit;





        $('.jieda-caina').click(function () {
            answer_id = $(this).attr('answer_id');
            $.ajax({
                url:"/answer/caina/"+answer_id,
                type: 'post',
                dataType: 'json',
                success: function (data) {
                    if(data.error ==1){
                        layer.msg(data.info, function(){
                        });
                    }else if(data.error ==0){
                        layer.alert(data.info, {icon: 6},function(){
                            location.reload();
                        });
                    }
                },
                fail: function (err) {
                    console.log(err)
                }
            })
        })

        $('.jieda-zan').click(function () {
            that = $(this)
            answer_id =  $(this).attr('answer_id')
            zan = parseInt($(this).find('em').text());
            $.ajax({
                url:"{{url('/answer/zan')}}",
                type: 'post',
                data:{'answer_id':answer_id,},
                dataType: 'json',
                success: function (data) {
                    if(data.error ==1){
                        layer.msg(data.info, function(){
                        });
                    }else if(data.error ==0){
                        that.addClass('zanok');
                        location.reload();

                    }
                },
                fail: function (err) {
                    console.log(err)
                }
            })
        })
        $('.jie-admin').click(function () {
            $.ajax({
                url:"/question/collection/{{$question_id}}",
                type: 'post',
                dataType: 'json',
                success: function (data) {
                    if(data.error ==1){
                        layer.msg(data.info, function(){
                        });
                    }else if(data.error ==0){
                        layer.alert(data.info, {icon: 6},function(){
                            location.reload();
                        });
                    }
                },
                fail: function (err) {
                    console.log(err)
                }
            })
        })
        layedit.set({
            uploadImage: {
                url: "{{url('/question/upload')}}" //接口url
                ,type: 'post'
            }
        });
        thearea = layedit.build('L_content'); //建立编辑器
        $('.huifu').click(function () {
            uid = $(this).attr('uid');
            user =$(this).attr('nickname');
            $('.layui-textarea').text(user);
            layedit.sync(thearea);
        });
        form.on('submit(answerAdd)', function(data){
            data.field.content = layedit.getContent(thearea);
            $.ajax({
                url:"{{url('/answer/create')}}",
                type: 'post',
                data:data.field,
                dataType: 'json',
                success: function (data) {
                    if(data.error ==1){
                        layer.msg(data.info, function(){
                        });
                    }else if(data.error ==0){
                        layer.alert(data.info, {icon: 6},function(){
                            location.reload();
                        });
                    }
                },
                fail: function (err) {
                    console.log(err)
                },
                statusCode: {
                    // 422: function(data) {
                    //     layer.msg('有错误', function(){
                    //     });
                    // },
                    401: function(data) {
                        layer.msg('请先登录', function(){
                        });
                    }
                }
            })
            return false;
        });

    });
</script>
@endsection